﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using WeiSha.Core.Method;
using WeiSha.Core.Method.Snowflake;
using WeiSha.Core.Param.Method;
using WeiSha.Core.Parameters.Authorization;

namespace WeiSha.Core
{
	// Token: 0x02000023 RID: 35
	public class Request
	{
		// Token: 0x1700005F RID: 95
		// (get) Token: 0x0600010E RID: 270 RVA: 0x0000812C File Offset: 0x0000632C
		public static Request QueryString
		{
			get
			{
				return Request._queryString;
			}
		}

		// Token: 0x17000060 RID: 96
		// (get) Token: 0x0600010F RID: 271 RVA: 0x00008144 File Offset: 0x00006344
		public static Request Form
		{
			get
			{
				return Request._form;
			}
		}

		// Token: 0x17000061 RID: 97
		// (get) Token: 0x06000110 RID: 272 RVA: 0x0000815C File Offset: 0x0000635C
		public static Request Cookies
		{
			get
			{
				return Request._cookies;
			}
		}

		// Token: 0x17000062 RID: 98
		// (get) Token: 0x06000111 RID: 273 RVA: 0x00008174 File Offset: 0x00006374
		public static Request Session
		{
			get
			{
				return Request._session;
			}
		}

		// Token: 0x17000063 RID: 99
		// (get) Token: 0x06000112 RID: 274 RVA: 0x0000818C File Offset: 0x0000638C
		public static PageInfo Page
		{
			get
			{
				return new PageInfo();
			}
		}

		// Token: 0x06000113 RID: 275 RVA: 0x000081A4 File Offset: 0x000063A4
		public static string GetObjectPropertyValue<T>(T t, string propertyname)
		{
			Type type = t.GetType();
			PropertyInfo property = type.GetProperty(propertyname);
			bool flag = property == null;
			string text;
			if (flag)
			{
				text = string.Empty;
			}
			else
			{
				object value = property.GetValue(t, null);
				bool flag2 = value == null;
				if (flag2)
				{
					text = string.Empty;
				}
				else
				{
					text = value.ToString();
				}
			}
			return text;
		}

		// Token: 0x17000064 RID: 100
		public ConvertToAnyValue this[string str]
		{
			get
			{
				HttpContext httpContext = HttpContext.Current;
				ConvertToAnyValue convertToAnyValue = new ConvertToAnyValue();
				string text = "";
				string requestType = this._requestType;
				string text2 = requestType;
				if (!(text2 == "QueryString"))
				{
					if (!(text2 == "Form"))
					{
						if (!(text2 == "Cookies"))
						{
							if (text2 == "Session")
							{
								bool flag = httpContext.Session != null && httpContext.Session[str] != null;
								if (flag)
								{
									bool flag2 = httpContext.Session[str].ToString().Trim() != "";
									if (flag2)
									{
										text = httpContext.Session[str].ToString();
									}
								}
							}
						}
						else
						{
							bool flag3 = httpContext.Request.Cookies[str] != null;
							if (flag3)
							{
								bool flag4 = httpContext.Request.Cookies[str].Value.Trim() != "";
								if (flag4)
								{
									text = httpContext.Request.Cookies[str].Value;
								}
							}
						}
					}
					else
					{
						bool flag5 = httpContext.Request.Form[str] != null;
						if (flag5)
						{
							bool flag6 = httpContext.Request.Form[str].Trim() != "";
							if (flag6)
							{
								text = httpContext.Request.Form[str];
							}
						}
					}
				}
				else
				{
					bool flag7 = httpContext.Request.QueryString[str] != null;
					if (flag7)
					{
						bool flag8 = httpContext.Request.QueryString[str].Trim() != "";
						if (flag8)
						{
							text = httpContext.Request.QueryString[str];
						}
					}
				}
				text = HTML.ClearTag(text, 0);
				convertToAnyValue.ParaValue = text;
				return convertToAnyValue;
			}
		}

		// Token: 0x17000065 RID: 101
		// (get) Token: 0x06000115 RID: 277 RVA: 0x00008408 File Offset: 0x00006608
		public static Request Controls
		{
			get
			{
				return Request._controls;
			}
		}

		// Token: 0x17000066 RID: 102
		public ConvertToAnyValue this[WebControl ctrl]
		{
			get
			{
				ConvertToAnyValue convertToAnyValue = new ConvertToAnyValue();
				string text = "";
				bool flag = ctrl is TextBox;
				if (flag)
				{
					text = ((TextBox)ctrl).Text.Trim();
				}
				bool flag2 = ctrl is Label;
				if (flag2)
				{
					text = ((Label)ctrl).Text.Trim();
				}
				convertToAnyValue.ParaValue = text;
				return convertToAnyValue;
			}
		}

		// Token: 0x06000117 RID: 279 RVA: 0x00008489 File Offset: 0x00006689
		private Request()
		{
		}

		// Token: 0x06000118 RID: 280 RVA: 0x0000849E File Offset: 0x0000669E
		private Request(string requestType)
		{
			this._requestType = requestType;
		}

		// Token: 0x06000119 RID: 281 RVA: 0x000084BA File Offset: 0x000066BA
		private Request(WebControl requestControlName)
		{
			this._requestControlName = requestControlName;
		}

		// Token: 0x0600011A RID: 282 RVA: 0x000084D8 File Offset: 0x000066D8
		public static int Random()
		{
			Random random = new Random();
			int num = random.Next(0, 1000);
			DateTime now = DateTime.Now;
			string text = now.Minute.ToString() + now.Millisecond.ToString() + num.ToString();
			return Convert.ToInt32(text);
		}

		// Token: 0x0600011B RID: 283 RVA: 0x00008538 File Offset: 0x00006738
		public static string Random(int VcodeNum, int type)
		{
			string text = "0,1,2,3,4,5,6,7,8,9,";
			string text2 = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,";
			string text3 = text2.ToUpper();
			string text4;
			switch (type)
			{
			case 0:
				text4 = text + text2 + text3;
				break;
			case 1:
				text4 = text;
				break;
			case 2:
				text4 = text2;
				break;
			case 3:
				text4 = text3;
				break;
			case 4:
				text4 = text3 + text2;
				break;
			case 5:
				text4 = text + text2;
				break;
			case 6:
				text4 = text + text3;
				break;
			default:
				text4 = text + text2 + text3;
				break;
			}
			text4 = text4.Substring(0, text4.Length - 1);
			string[] array = text4.Split(new char[] { ',' });
			string text5 = "";
			Random random = new Random();
			for (int i = 1; i < VcodeNum + 1; i++)
			{
				text5 += array[random.Next(array.Length)];
			}
			return text5;
		}

		// Token: 0x0600011C RID: 284 RVA: 0x00008630 File Offset: 0x00006830
		public static string UniqueID()
		{
			string text = string.Format("{0}{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), Guid.NewGuid().ToString());
			return new ConvertToAnyValue(text).MD5.ToLower();
		}

		// Token: 0x0600011D RID: 285 RVA: 0x00008684 File Offset: 0x00006884
		public static long Unique64ID()
		{
			byte[] array = Guid.NewGuid().ToByteArray();
			return BitConverter.ToInt64(array, 0);
		}

		// Token: 0x0600011E RID: 286 RVA: 0x000086AC File Offset: 0x000068AC
		public static long SnowID()
		{
			return Generate.Next();
		}

		// Token: 0x0600011F RID: 287 RVA: 0x000086C4 File Offset: 0x000068C4
		public static _Path Path(string fullName)
		{
			return new _Path(fullName, "");
		}

		// Token: 0x06000120 RID: 288 RVA: 0x000086E4 File Offset: 0x000068E4
		public static Position Position()
		{
			string ip = Browser.IP;
			return new Position(ip);
		}

		// Token: 0x06000121 RID: 289 RVA: 0x00008704 File Offset: 0x00006904
		public static Position Position(string lng, string lat)
		{
			return new Position(lng, lat);
		}

		// Token: 0x06000122 RID: 290 RVA: 0x00008720 File Offset: 0x00006920
		public static Position Position(decimal lng, decimal lat)
		{
			return new Position(lng, lat);
		}

		// Token: 0x06000123 RID: 291 RVA: 0x0000873C File Offset: 0x0000693C
		public static Position Position(string address)
		{
			return new Position(address, 1);
		}

		// Token: 0x17000067 RID: 103
		// (get) Token: 0x06000124 RID: 292 RVA: 0x00008758 File Offset: 0x00006958
		public static Domain Domain
		{
			get
			{
				return new Domain();
			}
		}

		// Token: 0x17000068 RID: 104
		// (get) Token: 0x06000125 RID: 293 RVA: 0x00008770 File Offset: 0x00006970
		public static string Version
		{
			get
			{
				string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
				Assembly assembly = Assembly.LoadFrom(baseDirectory + "\\bin\\Song.WebSite.dll");
				return assembly.GetName().Version.ToString();
			}
		}

		// Token: 0x06000126 RID: 294 RVA: 0x000087B0 File Offset: 0x000069B0
		public static string GetSize(ulong size)
		{
			string text = "";
			bool flag = size < 1024UL;
			if (flag)
			{
				text = size.ToString() + " Bit";
			}
			else
			{
				double num = size / 1024UL;
				num = Math.Round(num * 100.0) / 100.0;
				bool flag2 = num < 1024.0;
				if (flag2)
				{
					text = num.ToString() + " Kb";
				}
				else
				{
					double num2 = num / 1024.0;
					num2 = Math.Round(num2 * 100.0) / 100.0;
					bool flag3 = num2 < 1024.0;
					if (flag3)
					{
						text = num2.ToString() + " Mb";
					}
				}
			}
			return text;
		}

		// Token: 0x06000127 RID: 295 RVA: 0x00008894 File Offset: 0x00006A94
		public static string HttpGet(string url)
		{
			HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
			httpWebRequest.Method = "GET";
			httpWebRequest.MaximumAutomaticRedirections = 3;
			httpWebRequest.Timeout = 10000;
			httpWebRequest.UserAgent = "User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705";
			httpWebRequest.Accept = "*/*";
			httpWebRequest.KeepAlive = true;
			httpWebRequest.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.5");
			Stream responseStream = ((HttpWebResponse)httpWebRequest.GetResponse()).GetResponseStream();
			StreamReader streamReader = new StreamReader(responseStream);
			string text = streamReader.ReadToEnd();
			streamReader.Close();
			responseStream.Close();
			return text;
		}

		// Token: 0x06000128 RID: 296 RVA: 0x00008940 File Offset: 0x00006B40
		public static string HttpPost(string url, string json)
		{
			HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
			httpWebRequest.Method = "POST";
			httpWebRequest.ContentType = "application/json";
			bool flag = !string.IsNullOrWhiteSpace(json);
			if (flag)
			{
				byte[] bytes = Encoding.ASCII.GetBytes(json);
				httpWebRequest.ContentLength = (long)bytes.Length;
				using (Stream requestStream = httpWebRequest.GetRequestStream())
				{
					requestStream.Write(bytes, 0, bytes.Length);
				}
			}
			HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
			StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8);
			return streamReader.ReadToEnd();
		}

		// Token: 0x06000129 RID: 297 RVA: 0x00008A00 File Offset: 0x00006C00
		public static string HttpPost(string url)
		{
			return Request.HttpPost(url, string.Empty);
		}

		// Token: 0x0600012A RID: 298 RVA: 0x00008A20 File Offset: 0x00006C20
		public static void LoadFile(string url, string filepath)
		{
			using (WebClient webClient = new WebClient())
			{
				try
				{
					webClient.Headers.Add("User-Agent", "Chrome");
					webClient.DownloadFile(url, filepath);
				}
				catch (Exception ex)
				{
					string currentDirectory = Environment.CurrentDirectory;
					using (FileStream fileStream = new FileStream(currentDirectory + "error.txt", FileMode.Append))
					{
						StreamWriter streamWriter = new StreamWriter(fileStream);
						streamWriter.WriteLine(url);
						streamWriter.WriteLine(ex.Message);
						streamWriter.Flush();
						streamWriter.Close();
						fileStream.Close();
					}
				}
			}
		}

		// Token: 0x17000069 RID: 105
		// (get) Token: 0x0600012B RID: 299 RVA: 0x00008AF0 File Offset: 0x00006CF0
		public static Dictionary<string, string> Copyright
		{
			get
			{
				return WeiSha.Core.Copyright.Items;
			}
		}

		// Token: 0x0600012C RID: 300 RVA: 0x00008B08 File Offset: 0x00006D08
		public static DataTable EditionsChinese()
		{
			DataTable dataTable = new DataTable("Editions");
			foreach (PropertyInfo propertyInfo in typeof(Edition).GetProperties())
			{
				bool visible = Entity.Get.GetVisible(propertyInfo.Name);
				bool flag = !visible;
				if (!flag)
				{
					string text = Entity.Get[propertyInfo.Name];
					dataTable.Columns.Add(new DataColumn(text, propertyInfo.PropertyType));
				}
			}
			for (int j = 0; j < Edition.Level.Length; j++)
			{
				DataRow dataRow = dataTable.NewRow();
				Edition item = Edition.GetItem(j);
				item.Name = Edition.Level[j];
				foreach (PropertyInfo propertyInfo2 in item.GetType().GetProperties())
				{
					bool visible2 = Entity.Get.GetVisible(propertyInfo2.Name);
					bool flag2 = !visible2;
					if (!flag2)
					{
						string text2 = Entity.Get[propertyInfo2.Name];
						dataRow[text2] = propertyInfo2.GetValue(item, null);
					}
				}
				dataTable.Rows.Add(dataRow);
			}
			return dataTable;
		}

		// Token: 0x0600012D RID: 301 RVA: 0x00008C5C File Offset: 0x00006E5C
		public static DataTable Editions()
		{
			DataTable dataTable = new DataTable("Editions");
			foreach (PropertyInfo propertyInfo in typeof(Edition).GetProperties())
			{
				bool visible = Entity.Get.GetVisible(propertyInfo.Name);
				bool flag = !visible;
				if (!flag)
				{
					dataTable.Columns.Add(new DataColumn(propertyInfo.Name, propertyInfo.PropertyType));
				}
			}
			for (int j = 0; j < Edition.Level.Length; j++)
			{
				DataRow dataRow = dataTable.NewRow();
				Edition item = Edition.GetItem(j);
				item.Name = Edition.Level[j];
				foreach (PropertyInfo propertyInfo2 in item.GetType().GetProperties())
				{
					bool visible2 = Entity.Get.GetVisible(propertyInfo2.Name);
					bool flag2 = !visible2;
					if (!flag2)
					{
						dataRow[propertyInfo2.Name] = propertyInfo2.GetValue(item, null);
					}
				}
				dataTable.Rows.Add(dataRow);
			}
			return dataTable;
		}

		// Token: 0x04000053 RID: 83
		private string _requestType = "";

		// Token: 0x04000054 RID: 84
		private static readonly Request _queryString = new Request("QueryString");

		// Token: 0x04000055 RID: 85
		private static readonly Request _form = new Request("Form");

		// Token: 0x04000056 RID: 86
		private static readonly Request _cookies = new Request("Cookies");

		// Token: 0x04000057 RID: 87
		private static readonly Request _session = new Request("Session");

		// Token: 0x04000058 RID: 88
		private WebControl _requestControlName;

		// Token: 0x04000059 RID: 89
		private static readonly Request _controls = new Request(new TextBox());
	}
}
